<?php
ls_import('lslib/DataObject');

class Role extends DataObject
{
	var $context;
	var $perm ;
	
	function Role(&$context){
		parent::DataObject($context);
	}
	
	function setId ($id='')
	{
		$this->set('role_id',$id);
	}
	
	function getId ()
	{
		$this->get('role_id');
	}
	
	function addPermission($datas)
	{
		if(is_array($datas)){
			$keys = array_keys($datas);
			for($i = 0; $i<count($keys); $i++){
				if(!$this->hasUserPermission($datas[$keys[$i]])){
					array_push($this->perm,$datas[$keys[$i]]);
				}
			}
		}else{
			if(!$this->hasUserPermission($datas)){
				array_push($this->perm,$datas)	;
			}
		}
	}
	
	function getUserPermissions()
	{
		return $this->perm;
	}
	
	function hasUserPermission($key='')
	{
		return (in_array($this->perm,$key));
	}
	
	function getPermissions()
	{
		$data = array();
		if(is_array($datas)){
			for($i = 0; $i<count($this->role); $i++){
				$role = $this->role[$i];
				$keys = array_keys($role->getPermission());
				for($i = 0; $i<count($keys); $i++){
					if(!$this->hasUserPermission($datas[$keys[$i]])){
						array_push($this->perm,$datas[$keys[$i]]);
					}
				}
			}
		}
		return $data;
	}
	
	function hasPermission($key=''){
		$data = $this->getPermissions();
		return (in_array($data,$key));
	}
	
	
}

?>